import Http from './http'
import conf from '@/config'
import cookie from 'react-cookies'
const http = new Http()
export default http

export const Api = new Http({
  baseURL: conf.host.api,
  headers: {
    post: { 'Content-Type': 'application/json' },
    put: { 'Content-Type': 'application/json' }
  }
})

Api.$before_request = (config) => {
  const token = cookie.load('token')
  if (token) {
    config.headers.token = token
  }
}

Api.$after_response = (response) => {
  const { code, data, message } = response.data
  if (code === 1) {
    response.data = data
  } else {
    console.log(code, message)
  }
}
